package model

import "gorm.io/plugin/soft_delete"

const (
	RoleCodeForSys   = "sys"
	RoleCodeForAdmin = "admin"
	RoleCodeForUser  = "user"

	RoleIsSysY = 1
	RoleIsSysN = 2

	RoleIsOpenY = 1
	RoleIsOpenN = 2
)

var DefaultRoles = []Role{
	{
		RoleId:    1,
		RoleName:  "超级管理员",
		RoleCode:  RoleCodeForSys,
		RoleDesc:  "系统内置的超级管理角色",
		IsSys:     RoleIsSysY,
		IsOpen:    RoleIsOpenY,
		Creator:   "root",
		CreatorId: RootId,
	},
	{
		RoleId:    2,
		RoleName:  "管理员",
		RoleCode:  RoleCodeForAdmin,
		RoleDesc:  "系统内置的管理角色",
		IsSys:     RoleIsSysY,
		IsOpen:    RoleIsOpenY,
		Creator:   "root",
		CreatorId: RootId,
	},
	{
		RoleId:    3,
		RoleName:  "超级管理员",
		RoleCode:  RoleCodeForUser,
		RoleDesc:  "系统内置的用户角色",
		IsSys:     RoleIsSysY,
		IsOpen:    RoleIsOpenY,
		Creator:   "root",
		CreatorId: RootId,
	},
}

type Role struct {
	RoleId    int64                 `json:"roleId,string" gorm:"primaryKey;comment:'角色id'"`
	RoleName  string                `json:"roleName" gorm:"comment:'角色名称'"`
	RoleCode  string                `json:"roleCode"` // sys、admin、user
	RoleDesc  string                `json:"roleDesc" gorm:"comment:'角色描述'"`
	IsSys     int                   `json:"isSys" gorm:"comment:'是否为系统数据， 1-是  2-否'"`
	IsOpen    int                   `json:"isOpen" gorm:"comment:'是否公开， 1-是 2-否'"`
	Creator   string                `json:"creator" gorm:"comment:'创建者'"`
	CreatorId int64                 `json:"creatorId,string" gorm:"comment:'创建者id'"`
	CreatedAt int64                 `json:"createdAt,string" gorm:"autoUpdateTime:milli"`
	UpdatedAt int64                 `json:"updatedAt,string" gorm:"autoUpdateTime:milli"`
	DeletedAt soft_delete.DeletedAt `json:"-"`
}

func (u *Role) TableName() string {
	return "sys_role"
}
